<template>
  <div>
    <!-- 手动选择年月 -->
    <el-row :gutter="10">
      <el-col :offset="16" :span="4">
        <el-select v-model="year" clearable size="mini" @change="setDate">
          <el-option
            v-for="item in selectYear"
            :key="item"
            :value="item"
            :label="item"
          />
        </el-select>
      </el-col>
      <el-col :span="3">
        <el-select v-model="month" clearable size="mini" @change="setDate">
          <el-option
            v-for="item in 12"
            :key="item"
            :value="item"
            :label="item"
          />
        </el-select>
      </el-col>
    </el-row>
    <!-- 日历 -->
    <el-calendar v-model="currentValue">
      <template v-slot:dateCell="{ date }">
        <div class="cell-content">
          <span>{{ date.getDate() }}</span>
          <span v-if="selDay(date)">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  data() {
    return {
      year: '',
      month: '',
      selectYear: [],
      currentValue: new Date()
    }
  },

  created() {
    const date = new Date()
    this.year = date.getFullYear()
    this.month = date.getMonth() + 1
    this.selectYear = Array(11)
      .fill(this.year)
      .map((item, index) => item - 5 + index)
  },

  methods: {
    selDay(date) {
      return date.getDay() === 6 || date.getDay() === 0
    },
    setDate() {
      this.currentValue = new Date(this.year + '-' + this.month)
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-calendar__header {
  display: none;
}
::v-deep .el-calendar-table {
  .cell-content {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    span:nth-child(2) {
      background: #fa7c4d;
      display: inline-block;
      position: relative;
      top: -1px;
      width: 20px;
      height: 20px;
      line-height: 20px;
      font-size: 10px;
      border-radius: 50%;
      color: #fff;
      text-align: center;
      margin-left: 5px;
    }
  }
}

::v-deep .el-calendar-table tr td {
  border: none;
}
</style>
